package com.yanqu.road.server.cmd.activity.mammonhall;

import com.yanqu.road.entity.activity.mammonhall.MammonHallSourceDataInfo;
import com.yanqu.road.pb.activity.MammonHallProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.activity.mammonhall.CrossMammonHallMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;
import java.util.Map;

@Cmd(code = Protocol.C_MAMMON_HALL_SYNC_DATA, desc = "财神殿-数据同步")
public class CrossMammonHallSyncDataCmd extends CrossCommand {

    int type;
    List<MammonHallProto.CrossMammonHallSyncDataTemp> list;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        MammonHallProto.CrossMammonHallSyncDataRespMsg reqMsg = MammonHallProto.CrossMammonHallSyncDataRespMsg.parseFrom(packet.getBytes());
        type = reqMsg.getType();
        list = reqMsg.getValueList();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        for (Map.Entry<Integer, List<MammonHallSourceDataInfo>> listEntry : CrossMammonHallMgr.getSourceDataMap().entrySet()) {
            if(listEntry.getKey() != type){
                continue;
            }
            for (MammonHallSourceDataInfo dataInfo : listEntry.getValue()) {
                for (MammonHallProto.CrossMammonHallSyncDataTemp dataTemp : list) {
                    if(dataInfo.getUserId() == dataTemp.getUserId()){
                        dataInfo.setOtherString(dataTemp.getOtherValueList());
                    }
                }
            }
        }
    }

    @Override
    public void sendData() {

    }
}
